//百家号  图片转化
function imageDump(img_url){
	url = 'https://baijiahao.baidu.com/builderinner/api/content/file/image/dump?usage=content&is_waterlog=1&url='+img_url;
	result = '';

	$.ajax({
		url:url,
		type:"get",
		async:false,
		success:function(data){
			if(data.errno == 0){
				data = data.data;
				result = data;		 
			}
		},
		error:function(){
			layer.msg('百家图片转化异常');
		}
	})
	return result;
}

//文字转化
function textDump(text = ''){
	url = 'https://dd.youdnr.com/api/media/text';
	result = '';
	$.ajax({
		url:url,
		type:"post",
		async:false,
	    data:{
			'text':text
		},
		success:function(data){
			if(data.code == 200){
				result = data.result;
			}
		},
		error:function(){
			layer.msg('文字转化错误');
		}
	})
	return result;
}

//百家号 存草稿
function save(title,content,token){
	url = 'https://baijiahao.baidu.com/builder/author/article/save';
	result = '';
	data = {
		title: title,
		content: content,
		feed_cat:12,
		len: content.length,
		source_reprinted_allow: 0,
		original_status: 0,
		announce_id: 0,
		isBeautify: false,
		usingImgFilter: false,
		cover_layout: "one",
		cover_images: [],
		_cover_images_map: [],
		subtitle:'' ,
		bjhtopic_id:'' ,
		bjhtopic_info:'' ,
		type: "news"
	};
	$.ajax({
		url:url,
		type:"post",
		headers:{
			token:token
		},
		async:false,
	    data:data,
		success:function(data){
			console.log(data);
			if(data.errno == 0){
				result = true;
			}
		},
		error:function(){
			layer.msg('百家号上传异常');
		}
	})
	return result;
}

//获取response header
function getToken(){
	url = 'https://baijiahao.baidu.com/builder/app/appinfo?';
	result = '';
	$.ajax({
		url:url,
		type:"get",
		async:false,
		success:function(data,textStatus,request){ 
              token = request.getResponseHeader('token');
			  if(token){
				  result = token;
			  }
        },
		error:function(){
			layer.msg('百家号获取token失败');
		}
	})
	return result;
}